//
//  RoadShowCheckController.m
//  BigToBig
//
//  Created by liuyi on 7/25/16.
//  Copyright © 2016 cn.cloudtp. All rights reserved.
//

#import "RoadShowCheckController.h"
#import "EntrepreneurDetailView.h"
#import "DetailInfoCell.h"
#import "DetailMemberCell.h"
#import "RoadShowFunsCell.h"
#import "RoadShowUnexamineCell.h"
#import "RoadShowDetailHeadView.h"
#import "CountDown.h"

@interface RoadShowCheckController ()
<
UITableViewDelegate,
UITableViewDataSource
>
@property (nonatomic , retain)RoadShowDetailHeadView *roadShowDetailHeadView;
@property (nonatomic , retain)UITableView *mainTableView;

@property (nonatomic , retain)NSArray *sectionTitleArray;
@property (nonatomic , retain)NSString *info;

@property (strong, nonatomic)  CountDown *countDownForBtn;

@property (strong, nonatomic)  CountDown *countDownForLabel;

@end

@implementation RoadShowCheckController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self createData];
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"海水专卖";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    ///方法一倒计时测试
    long long startLongLong = 1467713971000;
    long long finishLongLong = 1497713974600;
    
    _countDownForLabel = [[CountDown alloc] init];
    _countDownForBtn = [[CountDown alloc] init];
    
    [self createView];
    
    [self startLongLongStartStamp:startLongLong longlongFinishStamp:finishLongLong];

}

#pragma mark - 占位数据
- (void)createData{
    self.sectionTitleArray = @[@"项目简介",@"项目粉丝",@"待审核",@"已报名"];
    self.info = @"天然海水不但可以卖给海产品批发商, 还可以晕倒城市里卖给各种海鲜酒楼.他们那些海产品不但要保鲜.还要放在玻璃缸中向顾客展示,海水对于他们更加重要.除此之外,城市里需要海水的地方还有一些海洋类观赏鱼养殖的地方等.其实在内陆地区有很多地方需要天然的海水,市场不小,但需要开发.海水专卖最大的投资是在运输方面.如果你的客户离海边不远,送水上门还没有什么困难.如果你的客户在内陆地区,你也许需要用火车来运输.";

}

#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
}

- (void)backController:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createView{
    // 创建头视图
    self.roadShowDetailHeadView = [[RoadShowDetailHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 265)];
    
    // 主tableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];
    self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, -70, 0);
    self.mainTableView.tableHeaderView = self.roadShowDetailHeadView;
    [self.view addSubview:_mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.rowHeight = 70;
    self.mainTableView.sectionHeaderHeight = 30;
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    [self.mainTableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:NSStringFromClass([DetailInfoCell class])];
    [self.mainTableView registerClass:[RoadShowUnexamineCell class] forCellReuseIdentifier:NSStringFromClass([RoadShowUnexamineCell class])];
    [self.mainTableView registerClass:[RoadShowFunsCell class] forCellReuseIdentifier:NSStringFromClass([RoadShowFunsCell class])];
    [self.mainTableView registerClass:[DetailMemberCell class] forCellReuseIdentifier:NSStringFromClass([DetailMemberCell class])];
    self.mainTableView.bounces = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
    self.mainTableView.tableFooterView = footerView;
    
    UIButton *reviewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    reviewButton.frame = CGRectMake(0, 0, kScreenWidth / 2, 50);
    [reviewButton setTitle:@"评分" forState:UIControlStateNormal];
    [reviewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    reviewButton.backgroundColor = [UIColor whiteColor];
    [reviewButton addTarget:self action:@selector(reviewButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:reviewButton];
    
    UIButton *focusButton = [UIButton buttonWithType:UIButtonTypeSystem];
    focusButton.backgroundColor = COLOR_RGBA(255, 81, 90, 1);
    focusButton.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 50);
    [focusButton setTitle:@"关注" forState:UIControlStateNormal];
    [focusButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [focusButton addTarget:self action:@selector(focusButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:focusButton];
    
}

#pragma mark - Button 点击方法

- (void)reviewButtonAction:(UIButton *)button{

    
}

- (void)focusButtonAction:(UIButton *)button{
    
}
///此方法用两个时间戳做参数进行倒计时
-(void)startLongLongStartStamp:(long long)strtLL longlongFinishStamp:(long long)finishLL{
    __weak __typeof(self) weakSelf= self;
    
    [_countDownForLabel countDownWithStratTimeStamp:strtLL finishTimeStamp:finishLL completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
            NSLog(@"second : %ld",second);
        [weakSelf refreshUIDay:day hour:hour minute:minute second:second];
    }];
}

-(void)refreshUIDay:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
    if (day==0) {
        self.roadShowDetailHeadView.dayLabel.text = @"0";
    }else{
        self.roadShowDetailHeadView.dayLabel.text = [NSString stringWithFormat:@"%ld",(long)day];
    }
    if (hour<10&&hour) {
        self.roadShowDetailHeadView.hourLabel.text = [NSString stringWithFormat:@"0%ld",(long)hour];
    }else{
        self.roadShowDetailHeadView.hourLabel.text = [NSString stringWithFormat:@"%ld",(long)hour];
    }
    if (minute<10) {
        self.roadShowDetailHeadView.minuteLabel.text = [NSString stringWithFormat:@"0%ld",(long)minute];
    }else{
        self.roadShowDetailHeadView.minuteLabel.text = [NSString stringWithFormat:@"%ld",(long)minute];
    }
    if (second<10) {
        self.roadShowDetailHeadView.secondLabel.text = [NSString stringWithFormat:@"0%ld",(long)second];
    }else{
        self.roadShowDetailHeadView.secondLabel.text = [NSString stringWithFormat:@"%ld",(long)second];
    }
}


#pragma mark - mainTableView代理方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    else if(section == 1){
        return 3;
    }
    else if (section == 2){
        return 3;
    }
    else if (section == 3){
        return 1;
    }
    else {
        return 0;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    UILabel *sectionTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.roadShowDetailHeadView.maxY, 30)];
    sectionTitle.text = self.sectionTitleArray[section];
    sectionTitle.font = [UIFont systemFontOfSize:15];
    [sectionView addSubview:sectionTitle];
    return sectionView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailInfoCell class]) forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.infoLabel.text = self.info;
        return cell;
    }
    else if (indexPath.section == 1){
        
        RoadShowFunsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RoadShowFunsCell class]) forIndexPath:indexPath];
        cell.titleLabel.text = @"那那那";
        cell.describeLabel.text = @"纯天然的无污染的.大大学生清华北大毕业,一本二本三本创作了什么项目呢哈哈哈,哈哈哈黄飞鸿金";
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        return cell;
    }
    else if (indexPath.section == 2){
        RoadShowUnexamineCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RoadShowUnexamineCell class]) forIndexPath:indexPath];
        cell.titleLabel.text = @"那那那";
        cell.describeLabel.text = @"纯天然的无污染的.大大学生清华北大毕业,一本二本三本创作了什么项目呢哈哈哈,哈哈哈黄飞鸿金";
        return cell;
    }

    else if (indexPath.section == 3){
        DetailMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailMemberCell class]) forIndexPath:indexPath];
        cell.titleLabel.text = @"那那那";
        cell.describeLabel.text = @"纯天然的无污染的.大大学生清华北大毕业,一本二本三本创作了什么项目呢哈哈哈,哈哈哈黄飞鸿金";
        return cell;
    }
    else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        // 计算文字的高度
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
        // 根据文本的内容和文本的字体进行计算高度
        // 参数一:告诉系统,文本显示的最大范围
        CGFloat width = (self.view.frame.size.width - 40);
        CGRect rect = [self.info boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        // 然后把图片的高和文本的高作为返回值返回
        return rect.size.height + 20;
    }
    else if (indexPath.section == 1){
        return 120;
    }
    else if (indexPath.section == 2){
        return 120;
    }
    else if (indexPath.section == 3){
        return 100;
    }

    else{
        return 50;
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
